package com.htu.hdfs;
import java.io.IOException;  
import java.net.URI;  
import java.net.URISyntaxException;  
import org.apache.hadoop.conf.Configuration;  
import org.apache.hadoop.fs.FSDataInputStream;  
import org.apache.hadoop.fs.FSDataOutputStream;  
import org.apache.hadoop.fs.FileStatus;  
import org.apache.hadoop.fs.FileSystem;  
import org.apache.hadoop.fs.Path;  
public class PutMerge {
	public static void main(String[] args) throws IOException, URISyntaxException {  
        Configuration conf = new Configuration();  
        String hdfsPath = "hdfs://localhost:9000";  
        FileSystem hdfs  = FileSystem.get(new URI(hdfsPath), conf);  
        FileSystem local = FileSystem.getLocal(conf);  
        String from_LinuxDir = "/data/hadoop4/";  
        String to_HDFS = "/hdfstest/mergefile";  
        FileStatus[] inputFiles = local.listStatus(new Path(from_LinuxDir));  
        FSDataOutputStream out = hdfs.create(new Path(to_HDFS));  
  
        for (FileStatus file : inputFiles) {  
            FSDataInputStream in = local.open(file.getPath());  
            byte[] buffer = new byte[256];  
            int bytesRead = 0;  
            while ( (bytesRead = in.read(buffer) ) > 0) {  
                out.write(buffer, 0, bytesRead);  
            }  
            in.close();  
        }  
        System.out.println("Finish!");  
    }  
}
